using B.S.BaseData.Domain.Entities.Logs;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.ErrorCode.ErrorCodes;
using B.S.BaseData.WriteAPI.Utils;
using B.S.DataBase.EFCoreServiers.Dtos.Depts;
using B.S.DataBase.EFCoreServiers.Dtos.Logs;
using B.S.DataBase.EFCoreServiers.IServices.Logs;
using B.S.DataBase.EFCoreServiers.Services.Depts;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace B.S.BaseData.WriteAPI.Controllers
{
    /// <summary>
    /// 操作日志控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    [Authorize]
    [ApiExplorerSettings(GroupName = "OperationLog")]
    public class OperationLogController : ControllerBase
    {
        private readonly IOperationLogServices _logServices;

        public OperationLogController(IOperationLogServices logServices)
        {
            _logServices = logServices;
        }

        /// <summary>
        /// 日志新增
        /// </summary>
        /// <param name="logDto"></param>
        /// <returns></returns>
        [HttpPost]
        [LogOperation("日志管理", "新增", "添加操作日志")]
        public async Task<ApiResult> AddOperationLogs(AddOperationLogDto logDto)
        {
            try
            {
                return await _logServices.AddOperationLogs(logDto);
            }
            catch (Exception ex)
            {
                return ApiResult.Fail("添加操作日志失败：" + ex.Message, StatusCodeEnum.Exception);
            }
        }

    }
}